<template>
  <div id="app">
   <router-view></router-view>
   <div class="progress" v-show="showprogress">
       <mu-circular-progress :size="40"/>
   </div>
    
  </div>
</template>

<script>
    require('./assets/js/kalendae.standalone.js');
    require('./assets/css/pay/kalendae.css');
    // require('muse-ui/dist/muse-ui.css'); //引入的scss
    require('./api/global/fanshe.global.js');
    require('./api/global/fanshe.mobile.ui.min-1.0.js');
    import {
        Toast
    } from 'mint-ui'

    import {
        mapState,
        mapGetters,
        mapMutations,
        mapActions
    } from 'vuex'
    export default {
        name: 'app',

        data() {
            return { //数据
                msg: 'wo'
            }
        },
        methods: { //方法
            opens(){
                //$.hsf.addcookie('wxopenid','ok1_As3K-U56TY7bOAAn-AEUHHtk',360000)
                //$.hsf.addcookie('wxopenid','123456',360000)
                $.local_Storage.setItem('wxopenid','ok1_As3K-U56TY7bOAAn-AEUHHtk')
                $.local_Storage.setItem('senderId',30)
                $.local_Storage.setItem('nickName','记忆中的红气球1')
                $.local_Storage.setItem('headimgurl','data.headimgurl')
            },
            getOpenid(){
                let vm = this;
                //let access_code=vm.getQueryString('code');
                /*let access_code = $.hsf.getcookie('code')
                let access_state = $.hsf.getcookie('state')*/
                let access_code = $.local_Storage.getItem('code')
                let access_state = $.local_Storage.getItem('state')
                let wxopenid = $.local_Storage.getItem('wxopenid')
                if (wxopenid == null || wxopenid == ''){
                    access_code=vm.getQueryString('code')
                    access_state=vm.getQueryString('state')
                    if (access_code==null || access_code == ''){
                        let fromurl="http://wx.fanshe360.com";
                        let url="https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx0a3951c5ecaf7ea1&redirect_uri="
                        +encodeURIComponent(fromurl)+"&response_type=code&scope=snsapi_userinfo"
                        +"&state=STATE%23wechat_redirect&connect_redirect=1#wechat_redirect";
                        location.href=url;
                    } else {
                        $.local_Storage.setItem('code',access_code)
                        $.local_Storage.setItem('state',access_state)
                        /*$.hsf.addcookie('code',access_code,360000)
                        $.hsf.addcookie('state',access_state,360000)*/
                        $.ajax({
                            type : "get",
                            async : false,
                            url : $.hsf.baseUrl + "/fanshe/wechar/getWXMassage.action?code=" +access_code+"&state=" + access_state,
                            dataType : "json",
                            processData : false,
                            success : function(data) {
                                //Toast(data.openId)
                                //alert(data.openid)
                                //alert(data.nickname)
                                //alert(data.headimgurl)
                                $.local_Storage.setItem('wxopenid',data.openid)
                                $.local_Storage.setItem('nickName',data.nickname)
                                $.local_Storage.setItem('headimgurl',data.headimgurl)
                                
                                /*$.hsf.addcookie('wxopenid',data.openId,360000); 
                                $.hsf.addcookie('nickName',data.nickName,360000);
                                $.hsf.addcookie('headimgurl',data.headimgurl,360000);*/
                                location.href="http://wx.fanshe360.com";
                            },
                            error : function() {
                                Toast('微信身份识别失败')
                            }
                        }); 
                    }
                }
            },
            getQueryString(name) {  
               let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");  
               let r = location.search.substr(1).match(reg);
               if (r != null)  
                   return unescape(decodeURI(r[2]));  
               return null;  
            }
        },
        computed: { //计算 用来引入vuex里面state
            ...mapGetters(['showprogress']),
            //...mapState(['openId'])
        },
        mounted: function() { //组件加载完成
            //this.getOpenid()
            this.opens()
        },
        watch: { //健康某个数据变化后触发某个事件

        },
        destroyed: function() { //离开这个组件

        },
        components: { //加载子组件
        }
    }
</script>

<style>
    /*@import 'muse-ui/dist/muse-ui.css';*/
    @import './assets/css/mintui.css';
    @import './assets/css/museui.css';
    @import './assets/css/public.css';
    @import './assets/css/base.css';
    @import './assets/css/theme.css';
    @import './assets/css/inoc.css';
    @import './assets/css/font.css';
    @import './assets/css/fanshe.mobile.ui-1.0.css';
    @import './assets/css/fanshe.mobile.ui.theme-1.0.css';
    .progress {
        display: flex;
        justify-content: center;
        align-items: center;
        top: 50%;
        left: 50%;
        position: fixed;
        -webkit-transform: translate(-50%, -50%);
        transform: translate(-50%, -50%);
    }
</style>